'use strict';

const Controller = require('egg').Controller;

class UserController extends Controller {
  async index() {
    const ctx = this.ctx;
    ctx.body = await ctx.model.User.findAll();
  }
  async create(){
    const ctx = this.ctx;
    // this.ctx.body = ctx.request.body;
    let result = await ctx.model.User.create({...ctx.request.body});
    ctx.body = result;
  }
  async destroy(){
    const ctx = this.ctx;
    const id = ctx.params.id;
    const user = await ctx.model.User.findByPk(Number(id));
    if(user){
      await user.destroy();
    }else{
      ctx.status = 404;
      return
    }
    ctx.body = id;
  }
  async update(){
    const ctx = this.ctx;
    ctx.body = 123;
  }
}

module.exports = UserController;
